package com.siyuan.blog.web.boke;


import com.baomidou.mybatisplus.plugins.Page;
import com.siyuan.blog.common.vo.LayTableResponse;
import com.siyuan.blog.domain.boke.Zuodh;
import com.siyuan.blog.domain.system.Role;
import com.siyuan.blog.domain.system.User;
import com.siyuan.blog.service.bokez.ZuodhService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/boker")
public class ZuodhController {
    @Autowired
    private ZuodhService zuodhService;

    /**
     * 跳转到列表页
     * @return
     */
    @RequestMapping("/ui/list")
    public String listUI(){

        return "boke/bokez/list";

    }

    /**
     * 跳转到添加页
     * @return
     */
    @RequestMapping("/ui/add")
    public String addUI(){

        return "boke/bokez/add";

    }

    /**
     * 跳转到添加页后保存
     * @return
     */
    @RequestMapping("/save")
    public String save(Zuodh zuodh){
        zuodhService.insert(zuodh);
        return "redirect:/boker/ui/list";//保存成功后跳转到列表页

    }

    /**
     * 跳转到编辑页
     * @return
     */
    @RequestMapping("/ui/edit")
    public String editUI(Integer id, ModelMap modelMap){
//        把要编辑的数据获取到
        Zuodh zuodh = zuodhService.selectById(id);
//        List<Role> roles = roleService.selectList(null);
        modelMap.put("zdh",zuodh);
        return "boke/bokez/edit";
    }

    /**
     * 列表页数据接口
     * @param page 表示当前页
     * @param limit 表示每页大小
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public LayTableResponse list(int page, int limit){
        Page<Zuodh> zuodhPage = zuodhService.selectPage(new Page<Zuodh>(page, limit),null);
        return new LayTableResponse(zuodhPage.getRecords(),zuodhPage.getTotal());
    }

    /**
     * 删除
     * @param
     * @return
     */
    @RequestMapping(path = "/delete")
    public String delete(@RequestParam("id") List<Integer> ids){
        zuodhService.deleteBatchIds(ids);
        return "redirect:/boker/ui/list";
    }

    /**
     *
     * @param
     * @return
     */
    @RequestMapping("/update")
    public String update(Zuodh zuodh){
        zuodhService.updateById(zuodh);
//        根据当前对象的ID修改
        return "redirect:/boker/ui/list";
    }
}
